//******************************************************************************
//this code is protected by the GNU affero GPLv3
//author:Sylvain BERTRAND <sylvain.bertrand AT gmail dot com>
//                        <digital.ragnarok AT gmail dot com>
//******************************************************************************
#include "globals.h"

//TODO:should go in the init of the registry shm object
//our supported formats for the pool
#define FMTS_N 2
static s8 fmts[FMTS_N]={
  [0]=WL_SHM_FORMAT_ARGB8888,
  [1]=WL_SHM_FORMAT_XRGB8888
};

s8 shm_bind_post(struct client *c,s32 name,u32 shm_id)
{
  (void)name;
  s8 r=LWL_OK;
  s8 fmt=0;
  while(1){
    if(fmt==FMTS_N) break;
    r=wl_shm_ev_format(c,shm_id,(u32)fmts[fmt]);
    if(r==LWL_ERR) break;
    ++fmt;
  }
  return r;
}

s8 shm_create_pool(struct client *c,u32 shm_pool_id,i fd,s32 sz)
{
  s8 r=shm_pool_new_visible(c,shm_pool_id,fd,sz);
  if(r==LWL_ERR)
    PERR("client(%d):shm::create_pool unable to create new shm pool\n",c->so);
  return r;
}
